<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition template="/Negozio/templateNegozio.xhtml"
                xmlns="http://www.w3.org/1999/xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:ui="http://java.sun.com/jsf/facelets">

    <ui:define name="pannello">

        <h:panelGrid columns="1">

            <p:growl id="msg" showDetail="false" autoUpdate="true"/> 

            <h:form id="ordini">

                <p:dataTable id="ordiniTabella" value="#{gestioneNegozio.ottieniOrdiniConfermati()}" var="o" emptyMessage="#{msg.ordiniEmpty}" style="width: 650px" paginator="true" rows="20"> 

                    <f:facet name="header">

                        <h:outputText value="#{msg.spedizioneOrdineTable}"/>
                    </f:facet>

                    <p:column style="width:2%">  
                        <p:rowToggler />  
                    </p:column> 

                    <p:column style="width:30%" headerText="#{msg.numeroOrdineTable}" sortBy="#{o.id}" filterBy="#{o.id}">  

                        <h:outputText value="#{o.id}" />  
                    </p:column>  

                    <p:column style="width:50%" headerText="#{msg.clienteTable}" filterBy="#{o.cliente.cognome}">  

                        <h:outputText value="#{o.cliente.nome} #{o.cliente.cognome}"/>

                    </p:column> 

                    <p:column style="width:20%" headerText="#{msg.totaleTable}" sortBy="#{o.totale}">  

                        <h:outputText value="#{o.totale}" />  
                    </p:column> 

                    <p:column>
                        <p:commandButton value="#{msg.spedisciOrdineButton}" actionListener="#{gestioneNegozio.spedisciOrdine(o)}" update=":ordini :msg :riepilogo" />
                    </p:column>

                    <p:rowExpansion>  

                        <p:panelGrid  columns="2" style="border: hidden">

                            <p:dataTable id="dettaglioOrdine" var="p" value="#{gestioneNegozio.ottieniProdottiDaOrdine(o.id)}" style="width: 280px">

                                <p:column headerText="#{msg.prodottoTable}" >

                                    <h:outputText value="#{p.prodotto.nome}"/>
                                </p:column>

                                <p:column headerText="#{msg.quantitaTable}" >

                                    <h:outputText value="#{p.quantità}"/>
                                </p:column>
                            </p:dataTable>

                            <p:panel id="dettaglioSpedizione" header="#{msg.spedizioneTable}">

                                <h:panelGrid columns="1" style="border: hidden; text-align: center">

                                    <h:outputText value="#{o.cliente.nome} #{o.cliente.cognome}"/>
                                    <h:outputText value="#{o.cliente.via}"/>
                                    <h:outputText value="#{o.cliente.cap} #{o.cliente.comune.provincia.abbreviazione} #{o.cliente.comune.nome}"/>
                                </h:panelGrid>
                            </p:panel>
                        </p:panelGrid>
                    </p:rowExpansion>
                </p:dataTable>
            </h:form>

            <p:spacer/>

            <h:form id="riepilogo" style="margin-top: 30px">

                <p:dataTable id="riepilogoTabella" value="#{gestioneNegozio.ottieniOrdiniSpediti()}" var="o" emptyMessage="#{msg.ordiniEmpty}" paginator="true" rows="10"> 

                    <f:facet name="header">

                        <h:outputText value="#{msg.ordineRiepilogoSpedizione}"/>
                    </f:facet>

                    <p:column style="width:2%">  
                        <p:rowToggler />  
                    </p:column> 

                    <p:column style="width:30%" headerText="#{msg.numeroOrdineTable}" sortBy="#{o.id}" filterBy="#{o.id}">  

                        <h:outputText value="#{o.id}" />  
                    </p:column>  

                    <p:column style="width:50%" headerText="#{msg.clienteTable}" filterBy="#{o.cliente.cognome}">  

                        <h:outputText value="#{o.cliente.nome} #{o.cliente.cognome}"/>

                    </p:column> 

                    <p:column style="width: 30%" headerText="#{msg.dataTable}" sortBy="#{o.dataOrdine}">
                        <h:outputText value="#{o.dataOrdine}"/>
                    </p:column>

                    <p:column style="width:20%" headerText="#{msg.totaleTable}" sortBy="#{o.totale}">  

                        <h:outputText value="#{o.totale}" />  
                    </p:column> 

                    <p:rowExpansion>  

                        <p:panelGrid  columns="2" style="border: hidden">

                            <p:dataTable id="dettaglioOrdine" var="p" value="#{gestioneNegozio.ottieniProdottiDaOrdine(o.id)}" style="width: 280px">

                                <p:column headerText="#{msg.prodottoTable}" >

                                    <h:outputText value="#{p.prodotto.nome}"/>
                                </p:column>

                                <p:column headerText="#{msg.quantitaTable}" >

                                    <h:outputText value="#{p.quantità}"/>
                                </p:column>
                            </p:dataTable>

                            <p:panel id="dettaglioSpedizione" header="#{msg.spedizioneTable}">

                                <h:panelGrid columns="1" style="border: hidden; text-align: center">

                                    <h:outputText value="#{o.cliente.nome} #{o.cliente.cognome}"/>
                                    <h:outputText value="#{o.cliente.via}"/>
                                    <h:outputText value="#{o.cliente.cap} #{o.cliente.comune.provincia.abbreviazione} #{o.cliente.comune.nome}"/>
                                </h:panelGrid>
                            </p:panel>
                        </p:panelGrid>
                    </p:rowExpansion>
                </p:dataTable>
            </h:form>
        </h:panelGrid>
    </ui:define>

</ui:composition>